package com.api.shopapi.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.api.shopapi.entity.EElderlyRelatives;
import com.api.shopapi.mapper.EElderlyRelativesMapper;
import com.api.shopapi.service.EElderlyRelativesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("EElderlyRelativesServiceImplOne")
public class EElderlyRelativesServiceImpl implements EElderlyRelativesService {

    @Autowired
    private EElderlyRelativesMapper elderlyRelativesMapper;

    @Override
    public int insert(EElderlyRelatives elderlyRelatives) {
        return elderlyRelativesMapper.insert(elderlyRelatives);
    }

    @Override
    public int update(EElderlyRelatives elderlyRelatives) {
        return elderlyRelativesMapper.update(elderlyRelatives);
    }

    @Override
    public int delete(String elderlyRelativesCode) {
        return elderlyRelativesMapper.delete(elderlyRelativesCode);
    }

    @Override
    public EElderlyRelatives getByElderlyRelativesCode(String elderlyRelativesCode) {
        return elderlyRelativesMapper.getByElderlyRelativesCode(elderlyRelativesCode);
    }

    @Override
    public PageInfo<EElderlyRelatives> getPageList(int pageIndex, int pageSize, String elderlyCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<EElderlyRelatives> elderlyRelativesList = elderlyRelativesMapper.getPageList(elderlyCode);
        return new PageInfo<>(elderlyRelativesList);
    }

    @Override
    @Transactional
    public void deleteAll(JSONArray elderlyRelativesCodeList) {
        for (int i=0;i<elderlyRelativesCodeList.size();i++){
            elderlyRelativesMapper.delete(elderlyRelativesCodeList.get(i).toString());
        }
    }
}
